package corbaEventService;

import java.util.UUID;

import org.omg.CORBA.Any;
import org.omg.CORBA.Object;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

import cosEventChannelAdmin.EventChannel;
import cosEventComm.Disconnected;
import cosEventComm.PushConsumer;
import cosEventComm.PushConsumerHelper;
import cosEventComm.PushConsumerPOA;


public class PushConsumerImpl extends PushConsumerPOA {
	private EventChannel channel;
	private String id;


	public PushConsumerImpl(EventChannel channel) {
		super();
		this.channel = channel;
		id = UUID.randomUUID().toString();
	}

	@Override
	public void push(Any data) throws Disconnected {
		channel.push(data);
	}

	@Override
	public void disconnect_push_consumer() {
		Object ref = null;
		try {
			ref = _poa().servant_to_reference(this);
		} catch (ServantNotActive e) {				
			e.printStackTrace();
		} catch (WrongPolicy e) {				
			e.printStackTrace();
		}
		
		PushConsumer supplier = PushConsumerHelper.narrow(ref);
		channel.disconnect_push_consumer(supplier);

	}

	@Override
	public String getID() {
		return id;
	}

}
